﻿<%@ WebHandler Language="C#" Class="detail" %>
using Models;
using System;
using System.Web;
using Newtonsoft.Json;
using System.Linq;
using Newtonsoft.Json.Linq;
using System.Collections;

public class detail : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";

        string authtoken = context.Request.Headers["X-ACCESS-USER"];//Header中的token
        if (string.IsNullOrEmpty(authtoken))
        {
            HttpContext.Current.Response.Write("parameter error");
            return;
        }
        var code = 1;
        var msg = "用户信息";
        var time = DateTime.Now;

        using (Entities bll = new Entities())
        {

            double mcount = 0;

            ArrayList list = new ArrayList();


            var _myresult = bll.S_Order.Where(p => p.ParentOopenID == authtoken&&p.OParentId==0);
            foreach (var x in _myresult)
            {
                double  money= (double)x.OLastPrice * 0.1;
                mcount += money;

                list.Add(new
                {
                    ID = x.OrderID,
                    uname = _rky.getUnamebyOPID(x.UGUID),
                    money= Math.Round(money,2),
                       time =Convert.ToDateTime(x.OCreatTime).ToString("yyyy-MM-dd HH:mm"),
                    x.OState
                }) ;


            };

            var  resultpp = bll.S_Order.Where(p => p.ParentParentOopenID == authtoken&&p.OParentId==0);
            foreach (var x in resultpp)
            {
             
                double  money= (double)x.OLastPrice * 0.03;
                mcount += money;

                list.Add(new
                {
                    ID = x.OrderID,
                    uname = _rky.getUnamebyOPID(x.UGUID),
                    money= Math.Round(money,2),
                       time =Convert.ToDateTime(x.OCreatTime).ToString("yyyy-MM-dd HH:mm"),
                    x.OState
                }) ;

            };
            var  resultppp = bll.S_Order.Where(p => p.ParentParentParentOopenID == authtoken&&p.OParentId==0);
            foreach (var x in resultppp)
            {
                double  money= (double)x.OLastPrice * 0.02;
                mcount += money;
                 list.Add(new
                {
                    ID = x.OrderID,
                    uname = _rky.getUnamebyOPID(x.UGUID),
                    money= Math.Round(money,2),
                    time =Convert.ToDateTime(x.OCreatTime).ToString("yyyy-MM-dd HH:mm"),
                    x.OState
                }) ;
            };


            decimal mymycount = Convert.ToDecimal(mcount);
            context.Response.Write(JsonConvert.SerializeObject(new {code,msg,time,data=list,mymycount}));

        }

        HttpContext.Current.Response.End();
        //context.Response.Write("Hello World");


    }





    public bool IsReusable {
        get {
            return false;
        }
    }

}